﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InvoiceSample;
using CodeProject.Data.Entity;
using System.Data.Objects;
using TestProjectCS.Attributes;

namespace TestProjectCS
{
	[TestClass]
	public class ListTests : BaseInvoiceTests
	{
		/// <summary>
		/// Listing all invoices on DB.
		/// </summary>
		[TestMethod]
		public void ListAllInvoices()
		{
			using (var context = new SampleInvoiceContext())
			{
				var invq = from inv
						   in context.InvoiceSet
								.Include(p => p.Customer)
								.Include(p => p.Lines.First().Product.Supplier)
						   select inv;

				foreach (var item in invq)
				{
					this.ShowInvoice(item, "___ INVOICE");
				}
			}
		}

		/// <summary>
		/// Listing all customers, products and suppliers on DB.
		/// </summary>
		[TestMethod]
		public void ListCustomersProductsSuppliers()
		{
			Console.WriteLine("__ Customers:");
			foreach (Customer item in this.Customers.Values)
				Console.WriteLine("{0:000}: '{1}', {2}", item.ID, item.Name, item.Level);

			Console.WriteLine("__ Products:");
			foreach (Product item in this.Products.Values)
				Console.WriteLine("{0:000}: '{1}', {2}", item.ID, item.Label, item.SalePrice);

			Console.WriteLine("__ Suppliers:");
			foreach (Supplier item in this.Suppliers.Values)
				Console.WriteLine("{0:000}: '{1}', {2}", item.ID, item.Name, item.Address);
		}

		[TestMethod]
		public void ListCatalogFolders()
		{
			using (var context = new SampleInvoiceContext())
			{
				var query = from folder in context.CatalogFolderSet
								.Include(p => p.Parent)
							orderby folder.ID
							select folder;
				foreach (CatalogFolder folder in query)
				{
					if (folder.Parent == null)
						Console.WriteLine("{0:0000} - {1}", folder.ID, folder.Name);
					else
						Console.WriteLine("{0:0000} - {1} (Parent : {2:0000})", folder.ID, folder.Name, folder.Parent.ID);
				}
			}
		}

		private object SampleInvoiceContext()
		{
			throw new NotImplementedException();
		}

		[TestMethod]
		public void Test()
		{
			Console.WriteLine(new SampleInvoiceContext().ObjectStateManager);
		}
	}
}
